package com.wmyg.antifake.repository;

import com.wmyg.antifake.entity.Product;
import com.wmyg.antifake.entity.Record;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-08
 */
@Repository
public interface RecordRepository extends JpaRepository<Record, Integer> {

    Integer countByProductAndBatchAndCreateTimeAfter(Product product, String batch, Date time);

    Record findByRecordId(Integer recordId);

    Record findByWxpayId(String wxpayId);

    Record findByAlipayId(String alipayId);

    Record findByExcelName(String excelName);

    Page<Record> findByProductIsInOrderByCreateTimeDesc(List<Product> products, Pageable pageable);

    Page<Record> findByProductIsInAndCreateTimeBeforeOrderByCreateTimeDesc(List<Product> products, Date endTime, Pageable pageable);

    Page<Record> findByProductIsInAndCreateTimeBetweenOrderByCreateTimeDesc(List<Product> products, Date startTime, Date endTime, Pageable pageable);

    Page<Record> findByProductIsInAndPayStateOrderByCreateTimeDesc(List<Product> products, Integer payState, Pageable pageable);

    Page<Record> findByProductIsInAndPayStateAndCreateTimeBeforeOrderByCreateTimeDesc(List<Product> products, Integer payState, Date endTime, Pageable pageable);

    Page<Record> findByProductIsInAndPayStateAndCreateTimeBetweenOrderByCreateTimeDesc(List<Product> products, Integer payState, Date startTime, Date endTime, Pageable pageable);

    Page<Record> findByProductIsInAndPayStateLessThanOrderByCreateTimeDesc(List<Product> products, Integer payState, Pageable pageable);

    Page<Record> findByProductIsInAndPayStateLessThanAndCreateTimeBeforeOrderByCreateTimeDesc(List<Product> products, Integer payState, Date endTime, Pageable pageable);

    Page<Record> findByProductIsInAndPayStateLessThanAndCreateTimeBetweenOrderByCreateTimeDesc(List<Product> products, Integer payState, Date startTime, Date endTime, Pageable pageable);

}
